<template>
<!--index.wxml-->
<view>
<view class="hotel-query">
  <!-- 轮播图banner -->
  <swiper :autoplay="autoplay" :interval="interval" :duration="duration" class="swiper-box">
    <block v-for="(item, index) in swiperImgs" :key="index">
      <swiper-item>
        <image :src="item.imgUrl" class="slide-image"></image>
      </swiper-item>
    </block> 
  </swiper>
  <!-- 搜索框 -->
  <view class="search-box">
		<view class="inv-h-w"> 
			<view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="choosetab(0)">全日</view> 
		  <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="choosetab(1)">钟点房</view>
		</view>
    <view class="search-item" @click="onShowDatePicker('range',range)" v-if="Inv == 0">
      <!-- 入住 -->
      <view class="date-item" hover-class="hover-class">
        <text>{{range[0].mouth}}月{{range[0].day}}日</text>
        <view class="check-info">
          <view>周{{range[0].week}}</view>
          <view>入住</view>
        </view>
      </view>
      <!-- 入住天数 -->
      <view class="date-item">
        <view class="check-days">
          <image src="/static/images/icon/icon_moon.png" class="check-moon"></image>
          <text>共{{timeFn(range[0].year+'/'+range[0].mouth+'/'+range[0].day,range[1].year+'/'+range[1].mouth+'/'+range[1].day)}}晚</text>
        </view>
      </view>
      <!-- 离店 -->
      <view class="date-item" hover-class="hover-class">
		  <view class="check-info">
		    <view>周{{range[1].week}}</view>
		    <view>离店</view>
		  </view>
        <text>{{range[1].mouth}}月{{range[1].day}}日</text>
      </view>
    </view>
    <view class="search-item" @click="onShowDatePicker('rangetime',range)" v-if="Inv == 1">
      <!-- 入住 -->
      <view class="date-item" hover-class="hover-class">
        <text>{{range[0].mouth}}月{{range[0].day}}日</text>
        <view class="check-info">
          <view>周{{range[0].week}}</view>
          <view>入住</view>
        </view>
      </view>
      <!-- 入住天数 -->
      <view class="date-item">
        <view class="check-days">
          <image src="/static/images/icon/icon_moon.png" class="check-moon"></image>
          <text>共{{timeFn(range[0].year+'/'+range[0].mouth+'/'+range[0].day+'/'+range[0].time,range[1].year+'/'+range[1].mouth+'/'+range[1].day+'/'+range[1].time,1)}}时</text>
        </view>
      </view>
      <!-- 离店 -->
      <view class="date-item" hover-class="hover-class">
      <view class="check-info">
        <view>周{{range[1].week}}</view>
        <view>离店</view>
      </view>
        <text>{{range[1].mouth}}月{{range[1].day}}日</text>
      </view>
    </view>
		 
		<view>
			<button style="background-color: #FFD327;color:#ffffff;" @tap="hotelhome()">立刻预订</button>
		</view>
  </view>
  <!-- <view v-if="supertest">您正处于小程序超级测试模式，此模式可测试肯天展厅功能</view> -->
  <sa-hover-menu v-if="supertest"></sa-hover-menu>
  <!-- 超级模式按钮结束 -->
	<view class="homebutton">
		<uni-grid :column="3">
		    <uni-grid-item v-if="equipmentlist.DOORLOCK.length != 0" @tap="navTo('/pages/controlbtn/btn')">
					<view class="contrallorbtn">
		        <image src="../../static/icon/mensuo.png" />
						<view>远程开门</view>
					</view>
		    </uni-grid-item>
		    <uni-grid-item v-if="equipmentlist.LIGHT.length != 0" @tap="navTo('/pages/controlbtn/index')">
					<view class="contrallorbtn">
		        <image src="../../static/icon/dengguang.png" />
		        <view>灯光控制</view>
					</view>
		    </uni-grid-item>
			<uni-grid-item v-if="equipmentlist.SCENE_TRIGGER.length != 0" @tap="navTo('/pages/controlbtn/model')">
					<view class="contrallorbtn">
			    <image src="../../static/icon/model.png" />
			    <view>情景模式</view>
					</view>
			</uni-grid-item> 		    
			<uni-grid-item v-if="equipmentlist.CURTAIN.length != 0" @tap="navTo('/pages/controlbtn/Curtain')">
					<view class="contrallorbtn">
		        <image src="../../static/icon/chuanglian.png" />
		        <view>控制窗帘</view>
					</view>
		    </uni-grid-item> 
				<uni-grid-item v-if="equipmentlist.AIR_CONDITION.length != 0" @tap="navTo('/pages/controlbtn/air')">
					<view class="contrallorbtn">
				    <image src="../../static/icon/kongtiao.png" />
				    <view>控制空调</view>
						</view>
				</uni-grid-item>
		</uni-grid>
	</view>
	<s-popup class="delaylist1" custom-class="center-popup" position="center" v-model="showCenterVisibleController">
		<view class="prompt">
			<view style="justify-content: center;padding-top: 20rpx; align-items: center;display: flex; padding-bottom: 15rpx;border-bottom:1rpx solid #828282;color: #353535; ">提示</view>
			<view style="padding: 30rpx;padding-bottom: 2rpx;">亲爱的客户：</view>
			<view style="padding: 30rpx;padding-bottom: 2rpx;padding-top: 2rpx;text-indent:2em;">您好！</view>
			<view style="padding: 30rpx;text-indent:2em;padding-top: 2rpx;">为保证您的安全，我们需要您在第一次进入房间或者重新登录后手动认证，用以确保是您本人使用，扫码后直至您在退房之前均可控制房间智能设备.</view>
			<image src="../../static/saoma.png" style="height: 370rpx;width: 400rpx;margin-left: 100rpx;"></image>
		</view>
		<view class="promptbtn">
			<view class="promptbtn-tittle promptbtn-tittle-no" @click="showCenterVisibleController = false">取消</view>
			<view class="promptbtn-tittle promptbtn-tittle-ok" hover-class="promptbtn-tittle-oka" @click="scanner(temporaryurl)">扫码验证</view>
		</view>
	</s-popup>
	
	<s-popup class="delaylist1" custom-class="center-popup" position="center" v-model="showCenterVisibleControllerToPhone">
		<view class="prompt">
			<view style="justify-content: center;padding-top: 20rpx; align-items: center;display: flex; padding-bottom: 15rpx;border-bottom:1rpx solid #828282;color: #353535; ">提示</view>
			<view style="padding: 30rpx;padding-bottom: 2rpx;">亲爱的客户：</view>
			<view style="padding: 30rpx;padding-bottom: 2rpx;padding-top: 2rpx;text-indent:2em;">您好！</view>
			<view style="padding: 30rpx;text-indent:2em;padding-top: 2rpx;">为您能顺利控制您入住的房间，我们需要您的手机号用于无感控制此房间设备.</view>
			<image src="../../static/saoma.png" style="height: 370rpx;width: 400rpx;margin-left: 100rpx;"></image>
		</view>
		<view class="promptbtn">
			<view class="promptbtn-tittle promptbtn-tittle-no" @click="showCenterVisibleControllerToPhone = false;showCenterVisibleControllerToPhone2=true">不绑定手机号</view>
			<view class="promptbtn-tittle promptbtn-tittle-ok" hover-class="promptbtn-tittle-oka" @click="tophone()">绑定手机号</view>
		</view>
	</s-popup>
	
	<s-popup class="delaylist1" custom-class="center-popup" position="center" v-model="showCenterVisibleControllerToPhone2">
		<view class="prompt">
			<view style="justify-content: center;padding-top: 20rpx; align-items: center;display: flex; padding-bottom: 15rpx;border-bottom:1rpx solid #828282;color: #353535; ">提示</view>
			<view style="padding: 30rpx;text-indent:2em;padding-top: 2rpx;">如果不绑定手机号，您需要每次控制输入验证信息</view>
			<image src="../../static/saoma.png" style="height: 370rpx;width: 400rpx;margin-left: 100rpx;"></image>
		</view>
		<view class="promptbtn">
			<view class="promptbtn-tittle promptbtn-tittle-no" @click="showCenterVisibleControllerToPhone2 = false">确定不绑定手机号</view>
			<view class="promptbtn-tittle promptbtn-tittle-ok" hover-class="promptbtn-tittle-oka" @click="tophone()">绑定手机号</view>
		</view>
	</s-popup>
	
	<s-popup class="delaylist1" custom-class="center-popup" position="center" v-model="showCenterVisibleControllerList">
		<view style="justify-content: center;padding-top: 20rpx; align-items: center;display: flex; padding-bottom: 15rpx;border-bottom:1rpx solid #828282;color: #353535; ">提示</view>
		<view style="padding: 30rpx;padding-bottom: 2rpx;">检测到您有多个入住房间，请手动选择</view>
		<view class="controllerlist">
			<view v-for="item in controllerRoomList" :class="controllerlistone == item.orderId?'controllerlist-tittleon':'controllerlist-tittle'" @click="controllerlistclick(item.orderId)">{{item.roomNumber}}</view>
		</view>
		<view class="promptbtn">
			<view class="promptbtn-tittle promptbtn-tittle-no" @click="showCenterVisibleControllerList = false">取消</view>
			<view class="promptbtn-tittle promptbtn-tittle-ok" hover-class="promptbtn-tittle-oka" @click="controllrtToeq">确定</view>
		</view>
	</s-popup>
	<s-popup class="delaylist2" custom-class="top-popup" position="top" v-model="showauthorization">
		<view style="display: flex;padding: 50rpx;flex-wrap: wrap;">
			<view v-for="item in authroomlist" style="display: flex;justify-content: center;align-items: center;flex-direction: column;margin:0 10rpx 10rpx 10rpx;" @click="supertestauth(item)">
				<view class="colorhead" :style="{background:ColorList[item.localId%4],'font-size': 24 - (item.roomName.length - 4)*3+ 'rpx'}">{{item.roomName}}</view>
				<view>{{item.roomName}}</view>
			</view>
			<view style="display: flex;justify-content: center;align-items: center;flex-direction: column;margin:0 10rpx 10rpx 10rpx;" @click="zanshi()">
				<view  class="colorhead1" style="border: #bcbcbc solid 1rpx;color: #bcbcbc;">+</view>
				<view>申请授权</view>
			</view>
			
		</view>
	</s-popup> 
	<s-popup class="delaylist1" custom-class="center-popup" position="center" v-model="showauth">
		<view style="justify-content: center;padding-top: 20rpx; align-items: center;display: flex; padding-bottom: 15rpx;border-bottom:1rpx solid #828282;color: #353535; ">提示</view>
		<view style="padding: 30rpx;padding-bottom: 2rpx;">检测到您有多个入住房间，请手动选择</view>
		<view class="controllerlist">
			<view v-for="item in controllerRoomList" :class="controllerlistone == item.orderId?'controllerlist-tittleon':'controllerlist-tittle'" @click="controllerlistclick(item.orderId)">{{item.roomNumber}}</view>
		</view>
		<view class="promptbtn">
			<view class="promptbtn-tittle promptbtn-tittle-no" @click="showCenterVisibleControllerList = false">取消</view>
			<view class="promptbtn-tittle promptbtn-tittle-ok" hover-class="promptbtn-tittle-oka" @click="controllrtToeq">确定</view>
		</view>
	</s-popup>
  <!-- 功能入口 -->
  <mx-date-picker :show="showPicker" :type="type" :value="value" :show-tips="true" :begin-text="'入住'" :end-text="'离店'" :show-seconds="true" @confirm="onSelected" @cancel="onSelected" />
</view>
</view>

</template>

<script module="filter" lang="wxs" src="../../filter/filters.wxs"></script>

<script>
//index.js
//获取应用实例
const app = getApp().globalData;
import saHoverMenu from '../../components/sa-hover-menu/sa-hover-menu.vue';
import {_getOneOrderEquipment,_getOrderEquipment,_getRoomDeviceInfo} from '../../common/vmeitime-http/controller.js';
import sPopup from '@/components/s-popup';
import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
import orderPage from "@/components/orderPage/orderPage.vue";
import uniGrid from "@/components/uni-grid/uni-grid.vue"
import uniGridItem from "@/components/uni-grid-item/uni-grid-item.vue"
import {screen} from "@/components/eqhading/eqhandling.js"
import {super_json} from "@/components/eqhading/super.js"
import {_getAutoRoom,_creatAutoRoom} from "@/common/vmeitime-http/auth.js"
let store =require("../utils/store.js")
// import {Room} from '@/api/room.js'
export default {
  data() {
    return {
		equipmentlist:uni.getStorageSync("equipmentlist"),
		showCenterVisibleControllerToPhone:false, // 手机号窗口
		showCenterVisibleControllerToPhone2:false, // 手机号窗口
		showauth:false,//授权窗口
		ColorList : ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'],
		authroomlist:[],//授权房间
		showauthorization:false,//授权弹窗标志位
		supertest:uni.getStorageSync("supertest"),
		controllerlistTourl:"",//房间控制列表选择
		controllerlistone:0,//房间控制列表选择
		showCenterVisibleControllerList:false,//房间控制列表选择弹窗标志位
		controllerRoomList:[], //房间控制列表
		temporaryurl:"", //临时url
		showCenterVisibleController:false, //弹窗标志位
      orderpageshow:false,
      animationData: {},
      showPicker:false,
	  range: [
			{
			year:"",
			mouth:"",
			day:"",
			week:"",
			time:"",
		},
		{
			year:"",
			mouth:"",
			day:"",
			week:"",
			time:"",
		}
		],
	  type: 'rangetime',
	  value: '',
      autoplay: true,
      interval: 3000,
      duration: 1000,
      imgMode: 'aspectFit',
      keyWordDisabled: true,
      priceStarDisabled: true,
      today: '',
      searchCondition: {
        address: '贵阳',
        checkIn: '',
        checkOut: ''
      },
      swiperImgs: [{
        imgUrl: "/static/images/index/ad_pic1.png",
        toUrl: ''
      }, {
        imgUrl: "/static/images/index/ad_pic1.png",
        toUrl: ''
      }],
      Inv:0,
      checkIn: "",
      checkOut: "",
	  dataPickerValue: [new Date(new Date().getTime() - 1 * 60 * 60 * 1000), new Date()]
    };
  },

 computed: {
    // 在计算属性中使用了闭包函数
    // changefont () {
    //   return function (leng) {
    //     return this.changefontsize(leng)
    //   }
    // }
  },

  components: {
	  MxDatePicker,
	  orderPage,
		uniGrid,
		uniGridItem,
		sPopup,
		saHoverMenu
  },
  props: {},
  onUnload() {
        this.animationData = {}
        // 页面关闭后清空数据
		
      },
  onLoad(){
	  this.equipmentlist = uni.getStorageSync("equipmentlist")
	  uni.setStorageSync("supertest",0) //每次进入页面退出超级模式
	  this.supertest=uni.getStorageSync("supertest")
	  console.log("------------------")
	  console.log(this.supertes)
          this.animation = uni.createAnimation()  
          // 创建动画实例
				console.log(uni.getStorageSync("equipmentlist"))
				console.log(uni.getStorageSync("controller"))	
      },

  /**
   * 页面显示
   */
  onShow() {
	  this.equipmentlist = uni.getStorageSync("equipmentlist")
	  wx.showShareMenu({
	    withShareTicket: true,
	    menus: ['shareAppMessage', 'shareTimeline']
	  })
	  // uni.setStorageSync("supertest",0) //每次进入页面退出超级模式
	  this.supertest=uni.getStorageSync("supertest")
	 let Version = 5
	if(!uni.getStorageSync("Version") || Version > uni.getStorageSync("Version")){
		uni.showModal({
			title:"小程序版本里程碑更新提示",
			content:"小程序重大更新，请重新登录",
			showCancel:false,
			success() {
				uni.clearStorageSync();
				uni.setStorageSync("Version",Version),
				uni.navigateTo({
					url:"../public/login_choose"
				})
			}
		})
	}
	
	
	
	
	
	this.showCenterVisibleController = false
    var app = getApp();
    console.log(app.globalData);
    let checkIn = 'searchCondition.checkIn',
        checkOut = 'searchCondition.checkOut';
		var time = new Date(+new Date(this.dataPickerValue[0])+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
		var time1 = new Date(+new Date(this.dataPickerValue[0])+24*60*60*1000+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
	this.range = [{year:time[0],mouth:time[1],day:time[2].split(' ')[0],week:this.dataChange(time[0],time[1],time[2].split(' ')[0]),time:time[2].split(' ')[1]},{year:time1[0],mouth:time1[1],day:time1[2].split(' ')[0],week:this.dataChange(time1[0],time1[1],time1[2].split(' ')[0]),time:time1[2].split(' ')[1]}];

	store.setItem("day",this.range)
  },

  methods: {
	  changefontsize(leng){
		if(leng<= 3){
			return 70-leng*14
		}else if(5>=leng >= 4){
			return 70-leng*10
		}
		return 12
	  },
	  closesuper(){
		  let that = this
		uni.showModal({
			title:"超级测试模式",
			content:"正在超级测试模式，是否退出",
			success(e) {
				// console.log(e)
				if(e.confirm){
					that.supertest = 0
					uni.setStorageSync("supertest",0)
					uni.showToast({
						icon:"none",
						title:"超级模式退出成功"
					})
				}
				
			}
		})  
	  },
	  controllerlistclick(num){
		  this.controllerlistone = num
	  },
	  controllrtToeq(){
		  
		  _getOneOrderEquipment({id:this.controllerlistone}).then(res =>{
			  console.log(res)
			  let obj= {
				  id:res.data.data.id,
				  hotleId:res.data.data.hotleId,
				  name:res.data.data.localId
			  }
			  uni.setStorageSync("controller",obj)
			  if(screen(res.data.data.equipmentExecutors)){
				  this.showCenterVisibleControllerList = false
			  	uni.navigateTo({
			  		url:this.temporaryurl
			  	})
			  }else{
			  	uni.showToast({
			  		icon:"none",
			  		title:"设备获取失败，请重试"
			  	})
			  }  
		  })
		  
		
	  },
		hotelhome(){
			uni.navigateTo({
				url: `/pages/hotelhome/index`
			})
			console.log("sssssss")
		}, 
		choosetab(e){
			this.Inv = e;
			if(e === 0){
				var time1 = new Date(+new Date(this.dataPickerValue[0])+24*60*60*1000+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
				var time = new Date(+new Date(this.dataPickerValue[0])+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
				this.range = [{year:time[0],mouth:time[1],day:time[2].split(' ')[0],week:this.dataChange(time[0],time[1],time[2].split(' ')[0]),time:time[2].split(' ')[1]},{year:time1[0],mouth:time1[1],day:time1[2].split(' ')[0],week:this.dataChange(time1[0],time1[1],time1[2].split(' ')[0]),time:time1[2].split(' ')[1]}];
			}else{
				var time = new Date(+new Date(this.dataPickerValue[0])+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
				var time1 = new Date(+new Date(this.dataPickerValue[0])+24*60*60*1000+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'').split("-")
					this.range = [{year:time[0],mouth:time[1],day:time[2].split(' ')[0],week:this.dataChange(time[0],time[1],time[2].split(' ')[0]),time:" "+time[2].split(' ')[1]},{year:time[0],mouth:time[1],day:time[2].split(' ')[0],week:this.dataChange(time[0],time[1],time[2].split(' ')[0]),time:" "+time[2].split(' ')[1]}];
				
			}
		},	
		ceshi(a){
			console.log(a)
			// http.get(Room+a).then(res => {
			// 			console.log(res)
			// 			})
		},
	dataChange(year,month,date) {
	   var dt = new Date(year, month-1, date);     
	   var weekDay = ["日", "一", "二", "三", "四", "五", "六"];
	   return weekDay[dt.getDay()];
	},
	
	onShowDatePicker(type,range){//显示
	if(type != "range"){
		var date = [range[0].year+'/'+range[0].mouth+'/'+range[0].day+'/'+range[0].time,range[1].year+'/'+range[1].mouth+'/'+range[1].day+'/'+range[1].time]
	}else{
		var date = [range[0].year+'/'+range[0].mouth+'/'+range[0].day,range[1].year+'/'+range[1].mouth+'/'+range[1].day]
	}
		
		console.log(range)
		this.type = type;
		this.showPicker = true;
		this.value = date;
	},
	onSelected(e) {//选择
		this.showPicker = false;
		console.log(e)
		if(e) {
			var date1 = e.value[0].split("/")
			var date2 = e.value[1].split("/")
			this.range = [{year:date1[0],mouth:date1[1],day:date1[2].split(' ')[0],week:this.dataChange(date1[0],date1[1],date1[2].split(' ')[0]),time:date1[2].split(' ')[1]},{year:date2[0],mouth:date2[1],day:date2[2].split(' ')[0],week:this.dataChange(date2[0],date2[1],date2[2].split(' ')[0]),time:date2[2].split(' ')[1]}] 
			//选择的值
			console.log('value => '+ e.value);
			store.setItem("day",this.range)
		}
	},
	timeFn(d1,d2,time) {//di作为一个变量传进来
	if(time === null){
		time:0
	}
	console.log(d1+' '+d2)
	    //如果时间格式是正确的，那下面这一步转化时间格式就可以不用了
	    var dateBegin = new Date(d1.replace(/-/g, "/"));//将-转化为/，使用new Date
	    var dateEnd = new Date(d2.replace(/-/g, "/"));//获取当前时间
	    var dateDiff = dateEnd.getTime() - dateBegin.getTime();//时间差的毫秒数
	    var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000));//计算出相差天数
	    var leave1=dateDiff%(24*3600*1000)    //计算天数后剩余的毫秒数
	    var hours=Math.floor(leave1/(3600*1000))//计算出小时数
	    //计算相差分钟数
	    var leave2=leave1%(3600*1000)    //计算小时数后剩余的毫秒数
	    var minutes=Math.floor(leave2/(60*1000))//计算相差分钟数
	    //计算相差秒数
	    var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数
	    var seconds=Math.round(leave3/1000)
			console.log(dateBegin+"  "+dateEnd)
			store.setItem("daytime",dayDiff)
			if(time ==  1){
				return hours;
			}else{
				return dayDiff;
			}
		
	    // console.log(" 相差 "+dayDiff+"天 "+hours+"小时 "+minutes+" 分钟"+seconds+" 秒")
	    // console.log(dateDiff+"时间差的毫秒数",dayDiff+"计算出相差天数",leave1+"计算天数后剩余的毫秒数"
	    //     ,hours+"计算出小时数",minutes+"计算相差分钟数",seconds+"计算相差秒数");
	},
	orderpage(index){
		this.roomdata = index;
		this.orderpageshow = true;
		this.running()
	},
	 running() {
	    this.animation = uni.createAnimation()	
			
		setTimeout(()=>{
			this.animation.translateY(-300).step({duration:200})
			this.animationData = this.animation.export()
			wx.hideTabBar({})
		}, 50);
	},
	orderclose(){
		wx.showTabBar({
			// animation:true
		})
		setTimeout(()=>{
			this.orderpageshow = false;
		}, 50);
		
		this.animation.translateY(300).step({duration:200})
		this.animationData = this.animation.export()
		
	},
	bookpage(id){
		uni.navigateTo({
			url: '../order/order?id='+id,
		});
	},
	/**
	 * 统一跳转接口,拦截未登录路由
	 * navigator标签现在默认没有转场动画，所以用view
	 */
	navTo(url){
		if(uni.getStorageSync("supertest") == 1){
			uni.removeStorageSync('equipmentlist');
			uni.removeStorageSync('controller');
			super_json()
			uni.navigateTo({
				url
			})
			return
		}
		if(uni.getStorageSync("supertest") == 2 || uni.getStorageSync("supertest") == 3){
			uni.navigateTo({
				url
			})
			return
		}
		if(!uni.getStorageSync('userInfo')){
			uni.navigateTo({
				url:"/pages/public/login_choose",
			})
			return
		}
		
		if(!uni.getStorageSync("userInfo").tel){
			this.showCenterVisibleControllerToPhone = true
		}else{
			_getOrderEquipment().then(res =>{
				if(!res.data.data){
					uni.showToast({
						icon:"none",
						title:"未找到您入住的房间信息"
					})
				}else if(res.data.data.id){
					let obj= {
									  id:res.data.data.id,
									  hotleId:res.data.data.hotleId,
									  name:res.data.data.localId
					}
					uni.setStorageSync("controller",obj)
					console.log(res.data.data.equipmentExecutors)
					if(screen(res.data.data.equipmentExecutors)){
						uni.navigateTo({
							url
						})
					}else{
						uni.showToast({
							icon:"none",
							title:"获取设备失败，请重试"
						})
					}
				}else{
					this.controllerRoomList = res.data.data
					this.temporaryurl = url
					this.showCenterVisibleControllerList = true
				}
				
				
				// if(!uni.getStorageSync("controller")){
				// 	this.showCenterVisibleController = true
				// 	this.temporaryurl = url
				// }else{
				// 	uni.navigateTo({
				// 		url
				// 	})
				// }
			}).catch( erro =>{
				console.log(erro)
			})
		}
		
		
		
		// uni.navigateTo({
		// 	url
		// })
	}, 
	tophone(){
		this.showCenterVisibleControllerToPhone = false
		this.showCenterVisibleControllerToPhone2 = false
		uni.navigateTo({
			url:"../user/update_tel"
		})
	},
	scanner(url){
		uni.scanCode({
		    onlyFromCamera: true,
		    success: function (res) {
		        console.log('条码类型：' + res.scanType);
		        console.log('条码内容：' + res.result);
				// console.log(res.path.split('?')[0] === "pages/controlbtn/sacncodeToOne")
				if(res.path.split('?')[0] === "pages/controlbtn/sacncodeToOne"){
					console.log(res.path)
					uni.navigateTo({
						url: '/'+res.path+'&url='+url
					})
				}else{
					uni.navigateTo({
						url: `/pages/controlbtn/sacncode?`+res.path.split('?')[1]+'&url='+url
					})
				}
				
				
				console.log(res)
		    }
		});
	},
	
	//下拉方法
	onPullDownRefresh() {
		if(!uni.getStorageSync('userInfo')){
			uni.navigateTo({
				url:"/pages/public/login_choose",
			})
			uni.stopPullDownRefresh();
			return
		}
		uni.vibrateShort({
		    success: function () {
		        console.log('success');
		    }
		});
		var that= this
		
		uni.request({
		  // url: 'http://127.0.0.1:9202/check/checkservice', //判断本地服务器
		  url: 'http://192.168.0.113:9202/check/checkservice', //判断本地服务器
		  success: function (e) {
			let aa = {
				ip: "121.32.52.3",
				openid : e.data.data
			}
			_getAutoRoom(aa).then( res =>{
				that.authroomlist = res.data.data
				uni.stopPullDownRefresh();
				that.showauthorization = true
				uni.vibrateLong({
					success: function () {
						console.log('success');
					}
				});
			})
		  },
		  fail:function(){
			uni.request({
			  url: 'https://pv.sohu.com/cityjson?ie=utf-8',
			  success: function (e) {
				var aaa = e.data.split(' ')[4].replace('"','').replace('"', '').replace(',', '');
				let aa = {
					ip: aaa,
					openid : uni.getStorageSync("userInfo").openid || ""
				}
				_getAutoRoom(aa).then( res =>{
					that.authroomlist = res.data.data
					uni.stopPullDownRefresh();
					that.showauthorization = true
					uni.vibrateLong({
						success: function () {
							console.log('success');
						}
					});
				})
			  },
			  fail:function(){
				console.log("失败了");
			  }
			})
		  }
		})
		
		
		
	},
	
	//获取想要控制的房间
	supertestauth(item){
		this.controllrtToeq(item.hotelId,item.localId)
	},
	
	//获取想要控制的设备
	controllrtToeq(hotel,roomnum){
		_getRoomDeviceInfo({str:this.str(hotel,roomnum)}).then( res => {
			uni.removeStorageSync('equipmentlist');
			uni.removeStorageSync('controller');
			let obj= {
			  id:res.data.data.id,
			  hotleId:res.data.data.hotleId,
			  name:res.data.data.name,
			  localId:res.data.data.localId,
			  realName:"李楠翔",
			  roomType:res.data.data.roomType
			}
			uni.setStorageSync("controller",obj)
			if(screen(res.data.data.equipmentExecutors)){
				uni.setStorageSync("supertest",3)
				this.supertest=uni.getStorageSync("supertest")
				this.showauthorization = false
				uni.showToast({
					icon:"none",
					title:"授权成功，请点击下方按钮控制"
				})
				
			}else{
				uni.showToast({
					icon:"none",
					title:"设备获取失败，请重试"
				})
			}  
		})
			
	},
	
	ranNun(len){
	    var number = ['0','1','2','3','4','5','6','7','8','9'];
	    var result = '';
	    for(var i = 0; i < len; i++){
	        var data = Math.ceil(Math.random() * 9);
	        result += number[data];
	    }
	    console.log(result);
	    return result;
	},
	addnum(length,num){
		return ((Array(length).join("0") + num).slice(-length)+"").split('').reverse().join('');
	},
	str(hotel,roomnum){
		// 获取当前日期
		var date = new Date();
		var strDate = date.getDate();
		console.log(strDate)
		let num = (strDate*1)%10
		if(num == 0){
			num = 10
		}
		let key = this.ranNun(num)+ this.addnum(4,hotel)+this.ranNun(num)+ this.addnum(8,roomnum)
		// console.log(key)
		return key
	},
	zanshi(n,t,e){
			var that= this
			// var ipc = [A,D,W,E,d,s,w,f,v,a]
			uni.request({
			      url: 'https://pv.sohu.com/cityjson?ie=utf-8',
			      success: function (e) {
			        var aaa = e.data.split(' ')[4].replace('"','').replace('"', '').replace(',', '');
					// for (var i = 0; i < aaa.length; i++) {
					// 	if(aaa[i] != ".")
					// 	aaa[i]=ipc[aaa[i]]
					// }
					let aa = aaa+","+uni.getStorageSync("userInfo").openid || ""
					uni.setClipboardData({
					  data: aa,
					  success (res) {
						  uni.showToast({
						  	icon:"none",
						  	title:"授权识别码已复制，请粘贴给授权人员"
						  })
					    uni.getClipboardData({
					      success (res) {
					        console.log(res.data) // data
					      }
					    })
					  }
					})
					// let aa = aaa+","+uni.getStorageSync("userInfo").openid || ""+","+n+","+t || ""+e || ""
					// console.log(aa)
			   //      _creatAutoRoom(aa).then( res =>{
						// that.onPullDownRefresh()
			   //      	uni.showToast({
			   //      		icon:"none",
			   //      		title:"成功"
			   //      	})
			   //      })
			      },
			      fail:function(){
			        console.log("失败了");
			      }
			    })
			
		// uni.showToast({
		// 	icon:"none",
		// 	title:"暂未开放"
		// })
	}
	
	

  }
};
</script>
<style lang="less">
/**index.wxss**/
/* 轮播图 */

.swiper-box {
  height: 452rpx;
}

.swiper-item {
  width: 750rpx;
  height: 100%;
}
.prompt{
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.promptbtn{
	display: flex;
	margin-top: 10rpx;
}
.promptbtn-tittle{
	flex: 1;
	display: flex;
	justify-content: center;
	align-items: center;
	height: 110rpx;
}
.promptbtn-tittle-ok{
	background-color: #FFD327;
	color: #FFFFFF;
}
.promptbtn-tittle-oka{
	background-color: #e1b521;
}
.promptbtn-tittle-no{
	background-color: #dedede;
	color: #5e5e5e;
}
/* 搜索框 */

.search-box {
  box-sizing: border-box;
  position: absolute;
  left: 50%;
  top: 400rpx;
  transform: translateX(-50%);
  width: 702rpx;
  height: 400rpx;
  background-color: #fff;
  border-radius: 5px;
  box-shadow: 0px 0px 20px 0px rgba(255, 122, 0, 0.3);
  padding: 0rpx 60rpx;
	display: flex;
	justify-content:space-around;
	flex-direction: column;

}
.hotel-query .s-popup-wrapper{
		width: 600rpx;
	}
	
.slide-image{
	width: 100%;
	
}

.search-item {
  font-size: 28rpx;
  color: #333;
  height: 94rpx;
  line-height: 90rpx;
  display: flex;
  justify-content: space-between;
}

.search-item:not(:first-child) {
  border-top: 1px solid #eee;
}

.show-address {
  display: inline-block;
  max-width: 400rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-address {
  float: right;
  color: #666;
  font-size: 24rpx;
}

.address-icon {
  width: 28rpx;
  height: 28rpx;
  position: relative;
  top: 4rpx;
  margin-right: 12rpx;
}

/* 入住天数 */

.date-item {
  width: 200rpx;
}
.date-item:nth-child(2){
  width: 160rpx;
}

.check-info {
  line-height: 30rpx;
  color: #999;
  font-size: 22rpx;
  float: right;
  margin-top: 14rpx;
}

.check-days {
  border-bottom: 1px solid #ff7a00;
  height: 64rpx;
  line-height: 70rpx;
  color: #ff7a00;
  text-align: center;
}

.check-moon {
  width: 20rpx;
  height: 23rpx;
  margin-right: 10rpx;
}

.search-ipt {
  width: 100%;
  height: 100%;
}

.search-ipt:-moz-placeholder {
  color: #999;
}

/* 查找btn */
.check-btn {
  height: 76rpx;
  width: 404rpx;
  float: left;
  background-color: #ff7a00;
  color: #fff;
  font-size: 32rpx;
}

.quick-btn {
  color: #ff7a00;
  width: 148rpx;
  height: 76rpx;
  font-size: 24rpx;
  float: right;
  border: 1px solid #ff7a00;
  border-radius: 5px;
  background-color: #fff1e5;
}
.icon-quick{
  float: left;
  width: 28rpx;
  height: 46rpx;
  margin-top: 15rpx;
  margin-left: 32rpx;
  margin-right: 12rpx;
}
.text-quick{
  float: left;
  width: 60rpx;
  line-height: 32rpx;
  margin-top: 4rpx;
}

/* 功能入口 */

.func-entrance {
  width: 100%;
  height: 180rpx;
  margin-top: 80rpx;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
}

.func-item {
  flex: 1;
  position: relative;
}

.func-item:not(:first-child)::after {
  content: '';
  position: absolute;
  top: 65rpx;
  width: 2rpx;
  height: 50rpx;
  background-color: #eee;
}

.func-icon {
  width: 42rpx;
  height: 36rpx;
  display: block;
  margin: 52rpx auto 20rpx;
}

.func-text {
  color: #333;
  font-size: 24rpx;
  text-align: center;
}

/* 酒店预订 */

.hotel-reservation {
  padding: 0 24rpx 10rpx;
}

.reservation-title {
  height: 90rpx;
  line-height: 90rpx;
  font-size: 32rpx;
  color: #333;
  text-align: center;
}

/* 酒店列表 */

.hotel-list {
  border-radius: 5px;
  background-color: #fff;
  box-shadow: 0px 0px 10px 0px rgba(170, 170, 170, 0.3);
  top: 1127px;
  width: 702rpx;
  height: 241rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
}

.hotel-pic {
  float: left;
  width: 200rpx;
  height: 100%;
}

.hotel-info {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-left: 210rpx;
  font-size: 28rpx;
  line-height: 48rpx;
  position: relative;
}

.hotel-name {
  color: #333;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hotel-score {
  color: #ff7a00;
  margin-right: 35rpx;
}

.hotel-star, .hotel-position {
  color: #666;
}

.hotel-position {
  font-size: 24rpx;
}

.hotel-distance {
  float: left;
}

.hotel-addr {
  display: inline-block;
  width: 260rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hotel-feature {
  border: 1px solid rgb(255, 122, 0);
  border-radius: 5px;
  background-color: rgb(255, 241, 229);
  height: 29rpx;
  color: #ff7a00;
  padding: 0 10rpx;
  margin-right: 12rpx;
}

.hotel-price {
  position: absolute;
  right: 0;
  bottom: 10rpx;
  background-color: rgb(255, 122, 0);
  width: 150rpx;
  height: 49rpx;
  border-radius: 10rpx 0 0 10rpx;
  text-align: center;
  color: #fff;
  font-size: 22rpx;
}

.price-num {
  font-size: 26rpx;
}

/* 预定页面 */

.orderpage{
	position: fixed;
	bottom: 0px;
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column-reverse;
	z-index: 999;
	background-color: rgb(127,127,127,0.5);
	
}

.order{
	background-color: #fff;
	height: 80%;
	border-radius:30rpx 30rpx 0 0;
	margin-bottom: -300px;
	box-shadow: 10px 10px 10px 10px rgba(115, 53, 0, 0.5);
}
.swiper-box-order{
	border-radius: 30rpx 30rpx 0 0;
}

.orderclose{
	position: fixed;
	top: 10rpx;
	left: 10rpx;
	color: #F6F3F1;
	z-index: 999999999999;
}

.ordertop{
	height: 20%;
	margin-bottom: 300px;
}

.inv-h-w{
	background-color: #FFFFFF;
	/* height: 80upx; */
	display: flex;
	}
.inv-h{
	font-size: 30upx;
	flex: 1;
	text-align: center;
	color: #C9C9C9;
	/* height: 100upx;
	line-height: 100upx; */
	}
.inv-h-se{
	color: #FFD327;
	/* border-bottom: 4upx solid #5BA7FF; */
	}
.homebutton{
	margin-top: 400rpx;
}
.contrallorbtn{
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding-top: 53rpx;

}
.homebutton uni-grid-item image{
	width: 80rpx;
	height: 80rpx;
	margin-bottom: 15rpx;
}


/* 弹窗 */
.controllerlist{
	display: flex;
	flex-wrap: wrap;
	padding: 22rpx;
}
.controllerlist-tittle{
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 15rpx;
	border-radius: 5rpx;
	border: #FFCF31 1rpx solid;
	margin: 20rpx;
	font-size: 40rpx;
	width: 100%;
}
.controllerlist-tittleon{
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 15rpx;
	border-radius: 5rpx;
	border: #FFCF31 1rpx solid;
	margin: 20rpx;
	font-size: 40rpx;
	width: 100%;
	background-color: #FFCF31;
	color: #FFFFFF;
}
.colorhead{
	border-radius: 50%;
	width: 100rpx;
	height: 100rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	color: #FFFFFF;
}
.colorhead1{
	border-radius: 50%;
	width: 98rpx;
	height: 98rpx;
	display: flex;
	justify-content: center;
	align-items: center;
	color: #FFFFFF;
}

.delaylist2{
	background-color: #FFFFFF;
	width: 700rpx;
	height: 300rpx;
	
	.s-popup-position-top .s-popup-wrapper{
		width: 100%;
	}
}
</style>